<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    // ES5继承:
        //创建父类 基类
        function Person(name,age) {
            //给实例对象扩展属性和方法
            this.name = name
            this.age = age
        }
        //扩展原型对象上的属性和方法,构造函数原型对象上的属性和方法
        Person.prototype.eat = function () {
            console.log("eat");
        }

        //子类
        function Student(id, name, age) {
            //构造函数继承
            Person.call(this, name, age)
            //扩展子类的属性和方法
            this.id = id
        }
        //原型链继承(不能直接把父类的原型对象赋值给子类的原型对象,否则会共享)
        Student.prototype = new Person
        //修正contructor,否则子类的constructor指向父类构造函数
        Student.prototype.constructor = Student

        Student.prototype.study = function () {
            console.log("node");
        }
    </script>
</body>
</html>